package com.cdc.log;

import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;

import com.cdc.interview.R;
import com.orhanobut.logger.AndroidLogAdapter;
import com.orhanobut.logger.FormatStrategy;
import com.orhanobut.logger.Logger;
import com.orhanobut.logger.PrettyFormatStrategy;

public class LogActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_log);
        FormatStrategy formatStrategy= PrettyFormatStrategy.newBuilder().tag("CDC").build();
        AndroidLogAdapter androidLogAdapter=new AndroidLogAdapter(formatStrategy);

        Logger.addLogAdapter(androidLogAdapter);
    }
    public void commonBtn(View view) {
//        Logger.t("123");
//        Logger.d("view commonBtn");
//        Logger.d("debug");
//        Logger.e("error");
//        Logger.w("warning");
//        Logger.v("verbose");
//        Logger.i("information");
//        Logger.wtf("What a Terrible Failure");
    }

    public void fileBtn(View view) {
        StackTraceElement[] trace = Thread.currentThread().getStackTrace();
        int a=getStackOffset(trace);
        Logger.d(trace.length+",a="+a);
    }

    private int getStackOffset(@NonNull StackTraceElement[] trace) {
        for (int i = 5; i < trace.length; i++) {
            StackTraceElement e = trace[i];
            String name = e.getClassName();
            if (!name.equals(Logger.class.getName())) {
                return --i;
            }
        }
        return -1;
    }
}
